package wyp.library.ui.tools;

import wyp.library.tools.WypSystemTool;
import android.view.ActionMode;
import android.view.ActionMode.Callback;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;

/**
 * 使EditText不能粘贴复制，比如说：需要输入2次密码，这时就不能让用户复制粘贴。
 * WypEditTextNotCopyHandler.handle(new EditText());
 * @author wuyiping
 *
 */
public class WypEditTextNotCopyHandler implements Callback {

	private static boolean isVersion11 = false;
	private static WypEditTextNotCopyHandler mCallback;
	static {
		isVersion11 = WypSystemTool.getSdkVersion() >= 11;
		mCallback = new WypEditTextNotCopyHandler();
	}

	public static void handle(EditText __editText) {
		__editText.setLongClickable(false);
		if (isVersion11) {
			__editText.setCustomSelectionActionModeCallback(mCallback);
		}
	}

	private WypEditTextNotCopyHandler() {
		super();
	}

	@Override
	public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
		return false;
	}

	@Override
	public boolean onCreateActionMode(ActionMode mode, Menu menu) {
		return false;
	}

	@Override
	public void onDestroyActionMode(ActionMode mode) {

	}

	@Override
	public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
		return false;
	}

}
